package com.xiaoyu.lanling.feature.gift.fragment

import `in`.srain.cube.views.list.CubeRecyclerViewSimpleAdapter
import `in`.srain.cube.views.list.ListPositionedItemBase
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.xiaoyu.lanling.view.OnShowFragment

abstract class AbstractGiftListFragment<GiftItem : ListPositionedItemBase> : OnShowFragment() {

    protected lateinit var mAdapter: CubeRecyclerViewSimpleAdapter<GiftItem>

    abstract fun getLayoutID(): Int

    abstract fun initAdapter()

    abstract fun selectFirstGift()

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(getLayoutID(), container, false)
    }

    override fun onShow() {
        super.onShow()
        selectFirstGift()
    }

    protected fun update(giftList: List<GiftItem>?) {
        mAdapter.list = giftList
        mAdapter.notifyDataSetChanged()
    }
}